<% @model = @version.item_type.constantize %>
<% @current_version = @model.find(@version.item_id) %>

<% differs = @version.reify.diff(@current_version).keys %>

<h1>Detail verze</h1>

<table class="table">
  <thead>
    <th><%= "#{t 'helpers.label.version.parameter'}" %></th>
    <th><%= "#{t 'helpers.label.version.difference'}" %></th>
  </thead>
  <tbody>
  <% @version.reify.attributes.each {|attr, value| %>
    <% banned_attrs = ["id", "created_at", "updated_at"] %>
    <% if banned_attrs.include?(attr): next end %>

    <% @diff = Differ.diff_by_word(value.to_s, @current_version.attributes.fetch(attr.to_s).to_s) %>

    <tr>
      <th <%= "style='color: red;'" if differs.include?(attr.to_sym) %>><%= t("helpers.label.#{@version.item_type.to_s.downcase}.#{attr.to_s.downcase}") %>:</th>
      <td><%= raw(@diff.format_as(:ascii)) %></td>
    </tr>
  <% } %>
  </tbody>
</table>
<%= button_to "Zpět", :back, :method => :get %>